<?php 
namespace app\admin\controller;

use app\common\controller\AdminBase;
use app\admin\model\System;
use app\admin\model\AdminUser;
use think\Db;

class Index extends AdminBase{
    protected function _initialize()
    {
        parent::_initialize();
        $this->assign('web',System::getValue('site_config'));
    }

	public function index()
    {
		return view('index');
	}
	/*站点动态展示*/
	public function webSite()
    {
        $version = Db::query('SELECT VERSION() AS ver');
        return view('config', ['mysql_version' => $version[0]['ver']]);
    }
    /*站点配置*/
    public function siteConfig()
    {
        $system = System::all();
        foreach($system as $key=>$val){
            $system_value = unserialize($val['value']);
            $this->assign($val['name'],$system_value);
        }
        return $this->fetch('site_config');
    }
    // 更新配置
    public function updateConfig()
    {
        if ($this->request->isAjax()) {
            $m = new System;
            $res = $m->updateConfig();
            return $res;
        }
    }
    /*修改密码*/
    public function changePassword()
    {
    	return view('change_password');
    }
    // 更新密码
    public function updatePassword()
    {
        if ($this->request->isAjax()) {
            $data   = input('post.');
            if(true === $result = $this->validate($data,'AdminUser')){
                $m = new AdminUser;
                $res = $m->updatePassword($data);
                return $res;
            }else{
                $this->error($result);
            }
        }
    }
}

